package com.own.stu.apm.plugins.mysql.interceptor;

import com.own.stu.apm.agent.core.plugin.interceptor.enhence.EnhenceInstanceField;
import com.own.stu.apm.agent.core.plugin.interceptor.enhence.InstanceMethodsAroundInterceptor;
import lombok.extern.slf4j.Slf4j;

import java.lang.reflect.Method;
import java.util.Arrays;

@Slf4j
public class MysqlInterceptor implements InstanceMethodsAroundInterceptor {

    public void beforeMethod(EnhenceInstanceField ojbIns, Method method, Object[] allArguments, Class<?>[] parameterTypes) {
        log.info("before mysql method name {}, arg: {}", method.getName(), Arrays.toString(allArguments));
    }

    public Object afterMethod(EnhenceInstanceField ojbIns, Method method, Object[] allArguments, Class<?>[] parameterTypes, Object ret) {
        log.info("after mysql method,  result: {}", ret);
        return ret;
    }

    public void handleEx(EnhenceInstanceField ojbIns, Method method, Object[] allArguments, Class<?>[] parameterTypes, Throwable t) {
        log.error("handleEx mysql ex ", t);
    }
}
